from scipy import zeros 
from scipy.linalg import norm
from constantes import G
from time import time

def Fr3(p1,p2,p3,m1,m2,m3):
    
    dx=zeros(6);
    dx[0:2]=p1/m1;
    dx[2:4]=p2/m2;
    dx[4:]=p3/m3; 
    return dx
   
    
def Fp3(r1,r2,r3,m1,m2,m3):

    a=time()
    #vetor espaco de fase:(p1x,p1y,p1z,p2x,p2y,p2z,p3x,p3y,p3z)
    
    dx=zeros(6);
    
    distancia12=norm(r1-r2);
    distancia13=norm(r1-r3);
    distancia23=norm(r2-r3);
    
    dx[0:2]=-(G*m1*m2*(r1-r2))/(distancia12**3)-(G*m1*m3*(r1-r3))/(distancia13**3);
    dx[2:4]=-(G*m2*m1*(r2-r1))/(distancia12**3)-(G*m2*m3*(r2-r3))/(distancia23**3);
    dx[4:]=-(G*m3*m1*(r3-r1))/(distancia13**3)-(G*m3*m2*(r3-r2))/(distancia23**3);
    b=time()
    print(b-a)
    return dx